# -*- coding: utf-8 -*-
from flask import Blueprint, make_response
from flask import send_file

from application.service.excel.pd_excel_service import PdExcel

pd_excel_bp = Blueprint('pd_excel', __name__)


@pd_excel_bp.get('/pd_export')
def pd_export():
    """Pandas Excel导出"""
    # 获取字节流

    output = PdExcel().export()
    return send_file(output, download_name='pd_excel.xlsx', as_attachment=True)


@pd_excel_bp.get('/pd_export_2')
def pd_export_2():
    """Pandas Excel导出"""
    # 获取字节流
    output = PdExcel().export()
    resp = make_response(output.getvalue())
    resp.headers["Content-Disposition"] = "attachment; filename=pd_excel.xlsx"
    resp.headers['Content-Type'] = 'application/x-xlsx'
    return resp

@pd_excel_bp.get('/export/csv')
def pd_export_csv():
    """Pandas CSV导出"""
    # 获取字节流

    output = PdExcel().export_csv()
    return send_file(output, download_name='pd_excel.csv', as_attachment=True)